<%@ page language="java" import="java.util.Calendar;" %>
<%@ page errorPage="error.jsp?source=creacionUsuario.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
 String ap = "";
 String n="";
 String a="";
 String f="01-01-1950";
 String sexo = "";
 String d = "";
 String e = "";
 String nac = "";
 char sx='X';
 double lttd=0;
 double lngt=0;

 String accion=request.getParameter("accion");
 if(accion!=null){	 
	 if(accion.equals("repetirPass")){
	 	ap = request.getParameter("apodo");
 		n=request.getParameter("nombre");
 	 	a=request.getParameter("apellidos");
 	 	f=request.getParameter("fechaN");
 	 	sexo = request.getParameter("sexo");
 	 	d = request.getParameter("direccion");
 	 	e = request.getParameter("email");
   	 	nac = request.getParameter("nacionalidad");
   	 	String lat = request.getParameter("lat");
   	 	String lng = request.getParameter("lng");
 	 	sx = sexo.charAt(0);
 	 	lttd = Double.valueOf(lat).doubleValue();
 	 	lngt = Double.valueOf(lng).doubleValue();
 	 	double[] loc=new double[2];
 	 	loc[0]=lttd;
 	 	loc[1]=lngt;	
 	}
 }
%>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>English Chicken</title>
  <link type='text/css' href='css/creacionUsuario.css' rel='stylesheet' media='all'>
  <script type="text/javascript" src="js/md5.js"></script>
  <script type="text/javascript" src="js/ajax.js"></script>
  <script type="text/javascript" src="js/creacionUsuario.js"></script>
  <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAG_EsipFAO3axUrlzBL54yBSES8lTjYXFoBn5xLctGYLEpAD2OBSBQIjzeyNIDc1gO06RLY5wfh7h-g"></script>
  <script type="text/javascript">
  var nuevaLatitud=<%=lttd%>;
  var nuevaLongitud=<%=lngt%>;
   function initialize(){
    if(GBrowserIsCompatible()){
     var map=new GMap2(document.getElementById("map_canvas"));
     map.setCenter(new GLatLng(0,0),1);
     map.addControl(new GLargeMapControl());
     map.addControl(new GMapTypeControl());
     <%
     int icono=sx=='H'?4:6;
     out.println("localiza("+lttd+","+lngt+","+icono+",map)");
     %>
    }
   }
  </script>  
 </head>
 <body onload="initialize()" onunload="GUnload()">
  <div id="gen_cont">
   <table>
    <tr>
     <td>Apodo*</td>
     <td><input type="text" name="apodo" id="apodo" value=<%=ap %>></td>
    </tr>
    <tr>
     <td>Contrase&ntilde;a*</td>
     <td><input type="password" name="passw1" id="passw1"></td>
    </tr>
    <tr>
     <td>Repita Contrase&ntilde;a*</td>
     <td><input type="password" name="passw2" id="passw2"></td>
    </tr>
    <tr>
     <td>Nombre</td>
     <td><input type="text" name="nombre" id="nombre" value=<%=n %>></td>
    </tr>
    <tr>
     <td>Apellidos</td>
     <td><input type="text" name="apellidos" id="apellidos" value=<%=a %>></td>
    </tr>
    <tr>
     <td>Fecha de Nacimiento</td>
     <td> 
    <% 
     Calendar today = Calendar.getInstance(); 
     int diaN = Integer.parseInt(f.substring(0, 2));
     int mesN = Integer.parseInt(f.substring(3, 5));
     int anyoN = Integer.parseInt(f.substring(6, 10));
     %>
     <select name="diaC" id="diaC">
     <%
     for(int dia=1;dia<32;dia++)
     {
    	 if(dia<10)
    	 {
    		 if(diaN==dia)
       		 	out.println("<option selected> 0" + dia + "</option>");   
       	 	else
       		 	out.println("<option> 0" + dia + "</option>");     
   		 
   		 }
   		 else
   		 {
   			 if(diaN==dia)
       			 out.println("<option selected>" + dia + "</option>");   
       		 else
       			 out.println("<option>" + dia + "</option>");     
   		 }
   	 
    	}
    %>
    </select>
     
    <select name="mesC" id="mesC" >
     <%
     for(int m=1; m<13;m++)
     {
    	 if(m<10)
    	 {
    		 if (mesN == m)
        		 out.println("<option selected> 0"+m+"</option>");
        	 else
        		 out.println("<option> 0"+m+"</option>");
    	 }
    	 else
    	 {
    	 if (mesN == m)
    		 out.println("<option selected>"+m+"</option>");
    	 else
    		 out.println("<option>"+m+"</option>");
    	 }
     }
    	 
     %>
   	 </select>
   	    	  
    <select name="yearC" id="yearC">
    
    <% 	   
    int year = today.get(Calendar.YEAR);
    for(int i=1950;i<year+1;i++)
    {
    	if(anyoN == i)
    		out.println("<option selected>"+i+"</option>");
    	else
    		out.println("<option>"+i+"</option>");
    
    }
    %>
     </select>
     </td>
    </tr>
    <tr>
     <td>Sexo</td>
     <td><input type="radio" name="sexo" value="H" <%if(sx=='H') out.println("checked ");  %> > Hombre <input type="radio" name="sexo" value="M" <%if(sx=='M') out.println("checked ");  %>> Mujer</td>
    </tr>
    <tr>
     <td>e-mail</td>
     <td><input type="text" name="email" id="email" value=<%=e %>></td>
    </tr>
    <tr>
     <td>Nacionalidad</td>
     <td><input type="text" name="nacionalidad" id="nacionalidad" value=<%=nac %> ></td>
    </tr>
    <tr>
     <td>Direcci&oacute;n</td>
     <td><input type="text" name="direccion" id="direccion" size="40" value=<%=d %>></td>
    </tr>
   </table>
   <br />
   <div id="map_canvas"></div>
   <br />
   <input type="button" value="Crear Usuario" onclick="enviar()"> <input type="reset" value="Restablecer" onclick="restablecer()">
   <br /><br />
   <hr />
   * Campos obligatorios.
  </div> 
 </body>
</html>